<?php
/**
 * @file commentreply.php
 * @author LJ (liangjian@haibao.com)
 * @date 2016年1月5日 上午11:51:18
 * @brief 
 */
namespace haibao\app\business;

class CommentReply extends \haibao\app\business\Base {

    /**
     * @var $_instance
     */
    private static $_instance;

    /**
     * instance()
     */
    private static function instance(){
        if(!self::$_instance){
            self::$_instance = new \haibao\app\data\CommentReply();
        }
        return self::$_instance;
    }
    
    /**
     * 回复评论列表
     */
    public static function getCommentReplyList($query){
        return self::instance()->getAll($query);
    }
    
    /**
     * 修改回复评论状态为已读
     */
    public static function setCommentReplyRead($replyIdArr){
        return self::instance()->setCommentReplyStatus($replyIdArr, \haibao\app\model\data\CommentReply::STATUS_YES);
    }
    
    /**
     * 根据用户Id修改所有评论回复消息状态为已读
     */
    public static function setReadReply($userId){
        if(!$userId){
            throw new BusinessException('参数不正确', self::DATA_ERROR_CODE_EMPTY);
        }
        if(self::getUnreadReplyCount($userId) > 0){
            self::instance()->setReadReplyByUserId($userId);
        }
    }
    
    /**
     * 删除回复评论
     */
    public static function deleteCommentReply($userId, $replyIdArr){
        if(!$replyIdArr){
            return false;
        }
        $replyIdArr = array_filter(array_unique($replyIdArr));
        self::instance()->setCommentReplyStatus($replyIdArr, \haibao\app\model\data\CommentReply::STATUS_DELETE, $userId);
    }
    
    /**
     * 查询未读回复评论数量
     */
    public static function getUnreadReplyCount($userId){
        if(!$userId){
            throw new BusinessException('参数不正确', self::DATA_ERROR_CODE_EMPTY);
        }
        return self::instance()->getUnreadReplyCount($userId);
    }
    
}